package sort;
//希尔排序
public class Shell {
    public static void sort(Comparable[] a){
        int h = 1;
        while (h< a.length){
            h=2*h+1;
        }
        while (h>0){
            for (int i = h;i<a.length;i++){
                for (int j = i; j>=h;j-=h){
                    if (grate(a[j-h],a[j])){
                        exch(a,j-h,j);
                    }
                }
            }
            h=h/2;
        }
    }
    //判断两个数值的大小
    private static Boolean grate(Comparable x, Comparable y){
        return x.compareTo(y) > 0;
    }
    //交换两个元素的位置
    private static void exch(Comparable[] a, int i ,int j){
        Comparable tem = a[i];
        a[i] = a[j];
        a[j] = tem;
    }
}
